//
//  CZMainTabBarController.swift
//  01-sinaWeibo-05-09
//
//  Created by mac on 16/5/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class CZMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //1先定义一个闭包
        let compseCallback = {()->() in
            
            print("Modal出控制器")
        }

        let mainTabBar = CZMainTabBar()
        
        //2传递闭包
        mainTabBar.compseCallback = compseCallback
        
        setValue(mainTabBar, forKey: "TabBar")
        setUpChilViewControllre()

    }
    func setUpChilViewControllre()
    {
        //首页
        let homeVC = CZHomeViewController()
        setUpChilViewControllre(homeVC, title: "首页", image: "tabbar_home")
        
        //消息
        let messageVC = CZMessageViewController()
        setUpChilViewControllre(messageVC, title: "消息", image: "tabbar_message_center")
       
        //发现
        let discoveryVC = CZDiscoveryViewController()
        setUpChilViewControllre(discoveryVC, title: "发现", image: "tabbar_discover")
       
        //我
        let profileVC = CZHomeViewController()
        setUpChilViewControllre(profileVC, title: "我", image: "tabbar_profile")
}
    func setUpChilViewControllre(controller: UIViewController,title: String,image:String )
    {
        //设置标题
        controller.title = title
        //设置图片
        controller.tabBarItem.image = UIImage(named:image)
        //设置高亮图片
        controller.tabBarItem.selectedImage = UIImage(named:image + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字选中的颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //包装导航控制器
//        UINavigationController(rootViewController: <#T##UIViewController#>))
        self.addChildViewController(UINavigationController(rootViewController:controller))
    }
}
